package com.sgb.kjwl.view.ui.adapter.self;

import android.content.Context;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.InviteComEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class InviteComAdapter extends BaseRecycleAdapter<InviteComEntity> {


    private onCheckListener onCheckClick;

    public interface onCheckListener {
        void onCheck();
    }

    public void setOnCheckClick(onCheckListener onCheckClick) {
        this.onCheckClick = onCheckClick;
    }


    public InviteComAdapter(Context context, List<InviteComEntity> datas) {
        super(context, R.layout.item_invite, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final InviteComEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        CheckBox checkBox = holder.itemView.findViewById(R.id.choose);

        checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                entity.setChoose(b);
                onCheckClick.onCheck();
            }
        });

        if (entity.getButtonStatus().equals("1")) {
            checkBox.setEnabled(false);
        } else {
            checkBox.setEnabled(true);
        }

        if (entity.isChoose()) {
            checkBox.setChecked(true);
        } else {
            checkBox.setChecked(false);
        }

    }
}
